package model;

import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * 
 * @author tyy
 *
 */
public class DataTable {
    private String myName;
    private List<Column<?>> myContent;
    /**
     * Creates a new Data Table.
     * @param tableName name of the table
     */
    public DataTable(String tableName) {
        myName = tableName;
        myContent = new ArrayList<Column<?>>();
    }
    /**
     * get the column by its number in the list of contents
     * @param columnNumber 
     * @return
     */
    public Column<?> getColumn(int columnNumber) {
        return myContent.get(columnNumber);
    }
    /**
     * get the column by its name
     * @param columnName 
     * @return
     */
    public Column<?> getColumn(String columnName) {
        for (Column<?> c : myContent) {
            if (c.getColumnName().equals(columnName)) {
                return c;
            }
        }
        return null;
    }
    /**
     * add a column to the table.
     * @param columnName 
     * @param content 
     */
    public void addColumn(String columnName, List<?> content) {
        myContent.add(new Column(myName, columnName, content));
    }
    /**
     * 
     * @return Returns a collection of Strings of column names.
     */
    public Collection<String> getColumnNames() {
        List<String> columnNames = new ArrayList<String>();
        for (Column<?> c : myContent) {
            columnNames.add(c.getColumnName());
        }
        return columnNames;
    }
    /**
     * 
     * @return The dimensions of the DataTable
     */
    public Dimension getSize() {
        Dimension size = (myContent.size() > 0) ? 
                new Dimension(myContent.size(), myContent.get(0).getContents().size()) : 
                new Dimension(0, 0);
        return size;
    }
}
